package io.renren.modules.jsf.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.jsf.dao.JsfGgaoDao;
import io.renren.modules.jsf.entity.JsfGgaoEntity;
import io.renren.modules.jsf.service.JsfGgaoService;


@Service("jsfGgaoService")
public class JsfGgaoServiceImpl extends ServiceImpl<JsfGgaoDao, JsfGgaoEntity> implements JsfGgaoService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<JsfGgaoEntity> page = null;
        if (StringUtils.isNotEmpty(key)) {
            page = this.page(
                    new Query<JsfGgaoEntity>().getPage(params),
                    new QueryWrapper<JsfGgaoEntity>().like("title", key).or()
                            .like("content", key)
            );
        } else {
            page = this.page(
                    new Query<JsfGgaoEntity>().getPage(params),
                    new QueryWrapper<JsfGgaoEntity>()
            );
        }

        return new PageUtils(page);
    }

}
